﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Vowei.Service.Excel;
using System.Linq.Expressions;
using Vowei.Data;

namespace vowei.test
{
    [TestClass]
    public class DataConnectionTest
    {
        [TestMethod]
        public void CreateOdcFileBasicTest()
        {
            var expected = 
                "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns=\"http://www.w3.org/TR/REC-html40\">\r\n" +
                "<head>\r\n" +
                "<meta http-equiv=Content-Type content=\"text/x-ms-odc; charset=utf-8\">\r\n" +
                "<meta name=ProgId content=ODC.Table>\r\n" +
                "<meta name=SourceType content=ODBC>\r\n" +
                "<title>Northwind</title>\r\n" +
                "<xml id=docprops>\r\n" +
                " <o:DocumentProperties xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns=\"http://www.w3.org/TR/REC-html40\">\r\n" +
                "  <o:Name>Northwind</o:Name>\r\n" +
                " </o:DocumentProperties>\r\n" +
                "</xml>\r\n" +
                "<xml id=msodc>\r\n" +
                "<odc:OfficeDataConnection xmlns:odc=\"urn:schemas-microsoft-com:office:odc\">\r\n" +
                "  <odc:Connection Type=\"ODBC\">\r\n"+
                "    <odc:ConnectionString>DRIVER=SQL Server;SERVER=mysqlserver;APP=2007 Microsoft Office system;Trusted_Connection=Yes</odc:ConnectionString>\r\n" +
                "    <odc:CommandText>SELECT * FROM Northwind.dbo.Invoices Invoices</odc:CommandText>\r\n" +
                "  </odc:Connection>\r\n" +
                "</odc:OfficeDataConnection>\r\n" +
                "</xml>\r\n" +
                "</head>\r\n" +
                "</html>";

            var connection = new OfficeDataConnection()
            {
                Connection = new CT_Connection()
                {
                    Type = ST_ConnectionType.ODBC,
                    ConnectionString = "DRIVER=SQL Server;SERVER=mysqlserver;APP=2007 Microsoft Office system;Trusted_Connection=Yes",
                    CommandText = "SELECT * FROM Northwind.dbo.Invoices Invoices"
                }
            };

            var actual = DataConnection.CreateOdcFile(connection, "Northwind");
            Assert.AreEqual(expected, actual);
        }
    }
}
